package com.vachel.editor.util;

import android.graphics.Bitmap;

import java.util.HashMap;
import java.util.Map;

public class BitmapManager {
    private static BitmapManager INSTANCE;

    private Map<String, Bitmap> mBitmaps;

    private BitmapManager() {
        mBitmaps = new HashMap<>();
    }

    public static BitmapManager getInstance() {
        if (INSTANCE == null) {
            INSTANCE = new BitmapManager();
        }
        return INSTANCE;
    }

    public void put(String key, Bitmap bitmap) {
        mBitmaps.put(key, bitmap);
    }

    public Bitmap get(String key) {
        if (mBitmaps.containsKey(key))
            return mBitmaps.get(key);
        else return null;
    }

    public void del(String key) {
        if (mBitmaps.containsKey(key)) {
            mBitmaps.get(key).recycle();
            mBitmaps.remove(key);
        }
    }
}
